import React, {Component, Fragment} from 'react';
import { Route, Switch, Redirect} from "react-router-dom"
import {userRouter} from "./routes";
import UserLayout from './components/UserLayout/index'
import { connect } from 'react-redux'

const mapStateToProps = (state,props) => {
    return {
        isUserLogin: state.user.isLogin
    }
}

@connect(mapStateToProps)
class User extends Component {
    render() {
        return (
            <Fragment>
                {
                    this.props.isUserLogin? <UserLayout>
                            <Switch>
                                {
                                    userRouter.map(routes => {
                                        return <Route path={routes.pathname} key={routes.key} component={routes.component} exact></Route>
                                    })
                                }
                                <Redirect to={userRouter[0].pathname} from='./user'></Redirect>
                            </Switch>
                        </UserLayout> :
                        <Redirect to='/login'></Redirect>
                }
            </Fragment>
        );
    }
}

export default User;